﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using ZLDC.Common.BaseUser;
using System.Data.SqlClient;
//using CrystalDecisions.CrystalReports.Engine;

namespace ZLDC.Common
{


    public class Report_Common
    {

        public static DateTime GetFirstDayOfMonth(int Year, int Month)
        {
            return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-1");
        }

        public static DateTime GetLastDayOfMonth(int Year, int Month)
        {
            int Days = DateTime.DaysInMonth(Year, Month);
            return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-" + Days.ToString());
        }

        public static DataTable GetDeptInfo(string beginTime, string endTime, string city, string type)
        {
            DateTime time1 = ZLDC.Common.Report_Common.GetFirstDayOfMonth(Convert.ToInt32(beginTime.Substring(0, 4)), Convert.ToInt32(beginTime.Substring(beginTime.IndexOf('-') + 1, 2)));
            DateTime time2 = ZLDC.Common.Report_Common.GetLastDayOfMonth(Convert.ToInt32(endTime.Substring(0, 4)), Convert.ToInt32(endTime.Substring(beginTime.IndexOf('-') + 1, 2)));

            DataBase db = new DataBase();

            SqlParameter param1 = new SqlParameter("@beginTime", SqlDbType.VarChar, 20);
            param1.Value = time1;
            SqlParameter param2 = new SqlParameter("@endTime", SqlDbType.VarChar, 20);
            param2.Value = time2;
            SqlParameter param3 = new SqlParameter("@city", SqlDbType.VarChar, 20);
            param3.Value = city;
            SqlParameter param4 = new SqlParameter("@type", SqlDbType.VarChar, 20);
            param4.Value = type;

            SqlParameter[] param = new SqlParameter[4] { param1, param2, param3, param4 };

            DataTable dt = db.ExecuteDataSet(ZLDC.Common.ConnectionString.ZLReport, CommandType.StoredProcedure, "Pro_GetDeptInfo", param);
            return dt;
        }

        //public static TextObject GetTextObject(ReportDocument myReport, string reportObjectName)
        //{
        //    TextObject text;

        //    text = myReport.ReportDefinition.ReportObjects[reportObjectName] as TextObject; if (text != null) return text;
        //    else return null;
        //}
    }
}
